package com.ccjq.jq167;

import java.sql.*;

public class DbConnection {

    private  static  final String DRIVER;
    private  static  final String URL;
    private  static  final String USERNAME;
    private  static  final String PASSWORD;

    static
    {
        DbConfigReader dbConfigReader=new DbConfigReader();
        DRIVER=dbConfigReader.getValue("driver");
        URL=dbConfigReader.getValue("url");
        USERNAME=dbConfigReader.getValue("username");
        PASSWORD=dbConfigReader.getValue("password");
    }
    //寤虹珛鏁版嵁搴撹繛鎺?

    public static Connection getConnextion()
    {
        Connection conn=null;
        try {
            Class.forName(DRIVER);
            conn= DriverManager.getConnection(URL,USERNAME,PASSWORD);


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static void close(ResultSet rs, Statement st,Connection conn)
    {

        try {
            if(rs!=null)
            {
                rs.close();
            }
            if(st!=null)
            {
                st.close();
            }
            if(conn!=null)
            {
                conn.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
